package com.zjxf.utils;

/**
 * Created with IntelliJ IDEA.
 *
 * @author zhang hao
 * date: 2018/9/25 14:51
 * description:
 */
public class UserUtils {



    /**
     * 获取加密密码
     *
     * @param account  账户
     * @param password 未加密密码
     * @param salt     盐
     * @return String
     */
    public static String getEncryptPassword(String account, String password, String salt) {
        byte[] hashPassword = Digests.sha1((account + password).getBytes(), Encodes.decodeHex(salt), Digests.HASH_INTERATIONS);
        return Encodes.encodeHex(hashPassword);
    }

    /**
     * 获取加密密码
     *
     * @param password 未加密密码
     * @param salt     盐
     * @return String
     */
    public static String getEncryptPassword(String password, String salt) {
        byte[] hashPassword = Digests.sha1(password.getBytes(), Encodes.decodeHex(salt), Digests.HASH_INTERATIONS);
        return Encodes.encodeHex(hashPassword);
    }

    public static void main(String[] args) {
        String salt = Encodes.encodeHex(Digests.generateSalt(Digests.SALT_SIZE));
        String encryptPassword = getEncryptPassword("Tysjcy@123.456", salt);
        System.out.println(salt);
        System.out.println(encryptPassword);
    }

}
